project(util LANGUAGES CXX)

file(GLOB SRCS "*.cpp" "*.hpp")
# file(GLOB_RECURSE SRCS "./*.cpp") # 递归搜索

foreach(cppfile IN LISTS SRCS)
    message(STATUS "Util process ${cppfile}")
endforeach()

set(CMAKE_BUILD_TYPE Debug)

add_library(util-shared SHARED
    ${SRCS}
)

# add_compile_options(util-shared -fPIC)

target_include_directories(util-shared PUBLIC
    ${util_SOURCE_DIR}/
    ${ip2region_SOURCE_DIR}/
    ${loguru_SOURCE_DIR}/
    ${pugixml_SOURCE_DIR}/
    ${FMT_SOURCE_DIR}/
    ${jsoncpp_SOURCE_DIR}/include
)

target_link_libraries(util-shared PUBLIC
    ip2region-static
    loguru-static
    pugixml::pugixml
    jsoncpp_static
    fmt::fmt-header-only
)

# unix、Windows下需要链接不同的库
if(${CMAKE_HOST_UNIX})
    target_link_libraries(util-shared PUBLIC
        dl # Linux下需要
    )
elseif(${CMAKE_HOST_WIN32})
    target_link_libraries(util-shared PUBLIC
        ws2_32 # windows下需要
    )
endif()

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")

    target_link_libraries(util-shared PUBLIC
        pthread # gcc下需要
    )
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
endif()
